home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / bash_114.zip / bash-1.14.2 / hash.h < prev    next >
C/C++ Source or Header  |  1994-04-16  |  2KB  |  62 lines

  1. /* hash.h -- the data structures used in hashing in Bash. */
  2.  
  3. /* Copyright (C) 1993 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Bash, the Bourne Again SHell.
  6.  
  7.    Bash is free software; you can redistribute it and/or modify it under
  8.    the terms of the GNU General Public License as published by the Free
  9.    Software Foundation; either version 2, or (at your option) any later
  10.    version.
  11.  
  12.    Bash is distributed in the hope that it will be useful, but WITHOUT ANY
  13.    WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14.    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15.    for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License along
  18.    with Bash; see the file COPYING.  If not, write to the Free Software
  19.    Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  20.  
  21. #if !defined (_HASH_H_)
  22. #define _HASH_H_
  23.  
  24. typedef struct bucket_contents {
  25.   struct bucket_contents *next;    /* Link to next hashed key in this bucket. */
  26.   char *key;            /* What we look up. */
  27.   char *data;            /* What we really want. */
  28.   int times_found;        /* Number of times this item has been found. */
  29. } BUCKET_CONTENTS;
  30.  
  31. typedef struct hash_table {
  32.   BUCKET_CONTENTS **bucket_array;    /* Where the data is kept. */
  33.   int nbuckets;            /* How many buckets does this table have. */
  34.   int nentries;            /* How many entries does this table have. */
  35. } HASH_TABLE;
  36.  
  37. extern int hash_string ();
  38. extern HASH_TABLE *make_hash_table ();
  39. extern BUCKET_CONTENTS *find_hash_item ();
  40. extern BUCKET_CONTENTS *remove_hash_item ();
  41. extern BUCKET_CONTENTS *add_hash_item ();
  42. extern BUCKET_CONTENTS *get_hash_bucket ();
  43.  
  44. /* Redefine the function as a macro for speed. */
  45. #define get_hash_bucket(bucket, table) \
  46.     ((table && (bucket < table->nbuckets)) ?  \
  47.         table->bucket_array[bucket] : \
  48.         (BUCKET_CONTENTS *)NULL)
  49.  
  50. /* Default number of buckets in the hash table. */
  51. #define DEFAULT_HASH_BUCKETS 107
  52.  
  53. #if !defined (NULL)
  54. #  if defined (__STDC__)
  55. #    define NULL ((void *) 0)
  56. #  else
  57. #    define NULL 0x0
  58. #  endif /* !__STDC__ */
  59. #endif /* !NULL */
  60.  
  61. #endif /* _HASH_H */
  62.